Imports Microsoft.VisualBasic
Imports System.Data.Sql
Imports System.Data
Imports System.Data.SqlClient
Imports SubSonic
Imports ClubStarterKit.Data

Namespace ClubStarterKit.Web
    Public Class Members

        <System.ComponentModel.DataObjectMethodAttribute _
        (System.ComponentModel.DataObjectMethodType.Select, False)> _
        Public Shared Function Getmembers(ByVal Filter As String) As IDataReader
            If Filter = "" Then
                Return MemberInfo.FetchAll()
            Else
                Return MemberInfo.FetchByParameter(MemberInfo.Columns.Lastname, SubSonic.Comparison.Like, Filter & "%")
                'When you are using the "Like" comparison, the % after the "Filter" means that it starts with the value of the filer
            End If
        End Function

        <System.ComponentModel.DataObjectMethodAttribute _
        (System.ComponentModel.DataObjectMethodType.Select, False)> _
        Public Shared Function ReturnLettersCount() As IDataReader
            Return SPs.MemberCountByLetter().GetReader()
        End Function

        Public Shared Function FirstAndLastName(ByVal memkey As Object) As String
            Dim str As String = ""
            Dim Mem As New MemberInfo(MemberInfo.Columns.Memberid, memkey)
            If Mem.IsLoaded = True Then
                str = Mem.Firstname
                str += " "
                str += Mem.Lastname
            End If
            Return str
        End Function

        <System.ComponentModel.DataObjectMethodAttribute _
        (System.ComponentModel.DataObjectMethodType.Select, False)> _
        Public Shared Function ListModerators() As IDataReader
            Dim rdr As IDataReader = SPs.ListModerators().GetReader()
            Return rdr
            rdr.Close()
        End Function

        Public Shared Sub DeleteUser(ByVal username As String)
            Dim mem As MembershipUser = Membership.GetUser(username)
            MemberInfo.Delete(MemberInfo.Columns.Memberid, mem.ProviderUserKey)
            Membership.DeleteUser(username, True)
            ProfileManager.DeleteProfile(username)
        End Sub

        Public Shared Sub DeleteUser(ByVal memguid As System.Guid)
            Dim mem As MembershipUser = Membership.GetUser(memguid)
            MemberInfo.Delete(MemberInfo.Columns.Memberid, mem.ProviderUserKey)
            Membership.DeleteUser(mem.UserName, True)
            ProfileManager.DeleteProfile(mem.UserName)
        End Sub

        Public Shared Sub DeleteUser()
            Dim mem As MembershipUser = Membership.GetUser()
            MemberInfo.Delete(MemberInfo.Columns.Memberid, mem.ProviderUserKey)
            Membership.DeleteUser(mem.UserName, True)
            ProfileManager.DeleteProfile(mem.UserName)
        End Sub

    End Class
End Namespace